package com.lin.order;


import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

@SpringBootApplication
@EnableDiscoveryClient
public class ServiceOrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceOrderApplication.class, args);
    }

    //1. 项目启动就监听配置文件变化
    //2. 配置文件变化就重新加载配置
    //3. 发送通知


    @Bean
    ApplicationRunner applicationRunner(NacosConfigManager nacosConfigManager){return args->{
        ConfigService configService = nacosConfigManager.getConfigService();
        configService.addListener("service-product.properties", "DEFAULT_GROUP", new Listener() {
            @Override
            public Executor getExecutor() {
                return Executors.newFixedThreadPool(4);
            }

            @Override
            public void receiveConfigInfo(String configInfo) {
                System.out.println("配置文件变化了："+configInfo);
            }
        });
    };

    }

}
